package com.sora.vod.controller;

import com.sora.commonutils.R;
import com.sora.commonutils.exceptionhandler.GuliException;
import com.sora.vod.service.VodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Classname: VodController
 * @Description:
 * @Author: Stonffe
 * @Date: 2023/1/9 17:30
 */
@RestController
@RequestMapping("/eduvod/video")
@CrossOrigin
public class VodController {
    @Autowired
    private VodService vodService;
    @PostMapping("uploadAliyunVideo")
    public R uploadAliyunVideo(MultipartFile file) {
        String s = vodService.uploadVideoAliyun(file);
        return R.ok().data("videoId",s);
    }
    @DeleteMapping("removeAliyunVideoById/{id}")
    public R removeAliyunVideoById(@PathVariable String id) {
        vodService.removeAliyunVideoById(id);
        return R.ok();
    }
    @DeleteMapping("/removeBatch")
    public R removeBatch(@RequestParam List<String> list) {
        vodService.removeMoreVideo(list);
        return R.ok();
    }
    //根据视频id获取视频凭证
    @GetMapping("/getPlayAuth/{id}")
    public R getPlayAuth(@PathVariable String id){
        try {
            String playAuth = vodService.getPlayAuth(id);
            return R.ok().data("playAuth",playAuth);
        } catch (Exception e) {
            e.printStackTrace();
            throw new GuliException(20001,"获取视频凭证失败");
        }

    }

}
